'use strict';
const Controller = require('egg').Controller;
/**
 * @controller BookController 书籍相关接口
 */
class ClassifyController extends Controller {
  async index() {
    /**
     * @description 查询类别
     * @router get /api/classify
     */
    const ctx = this.ctx;
    const result = await ctx.service.classify.getAllClassify();
    ctx.status = 200;
    ctx.body = result;
  }
  async addClassify() {
    /**
     * @description 新增类别
     * @router post /api/addClassify
     * @request body addClassify data  请求数据
     */
    const ctx = this.ctx;
    const data = ctx.request.body;
    const result = await ctx.service.classify.addClassify(data);
    ctx.status = 200;
    ctx.body = result;
  }
  async getClassifyById() {
    /**
     * @description 根据id获取分类
     * @router post /api/getClassifyById
     * @request query string id  分类id
     */
    const ctx = this.ctx;
    const classifyId = ctx.query.classifyId;
    const result = await ctx.service.classify.getClassifyById(classifyId);
    ctx.status = 200;
    ctx.body = result;
  }
  async updateClassify() {
    /**
     * @description 根据id更新分类
     * @router post /api/hideClassifyById
     */
    const ctx = this.ctx;
    const data = ctx.request.body;
    const result = await ctx.service.classify.updateClassify(data);
    ctx.status = 200;
    ctx.body = result;
  }
  async deleteClassifyById() {
    /**
     * @description 根据id删除某一个分类
     * @router post /api/deleteClassifyById
     * @request body  data  分类id
     */
    const ctx = this.ctx;
    const data = ctx.request.body;
    const result = await ctx.service.classify.deleteClassifyById(data.id);
    ctx.status = 200;
    ctx.body = result;
  }
}

module.exports = ClassifyController;
